/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sapra.dep.conexion;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.sapra.dep.*;
import org.sapra.Prefactura.PrefacturaMO;

/**
 *
 * @author Luis Guerrero
 */
public class DAC_Update extends DAC{
    public DAC_Update(){

    }

        public  void asignarTarjeta(int idRow,String num_tarjeta){
             DBWRAP pdb = new DBWRAP();
                ResultSet superRs;
                int idRs;
        String sql="UPDATE banorte_datarows SET num_tarjeta_debito='"+num_tarjeta+"' WHERE iddatarows="+idRow;
        try {
              pdb.update(sql);
        }catch(SQLException exs)
                {
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, exs);
                }catch(Exception ge){
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge);
                }finally {
                       try {
                               pdb.close();
                       }catch(Exception ge1){
                               Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge1);
                       }
                     }
    }

        public  void updateDataRow(ArrayList<DataRow> lista,int HeaderId){
            DataRow d=null;
             DBWRAP pdb = new DBWRAP();
                ResultSet superRs;
                int idRs;
              try {
                 for(int i=0;i<lista.size();i++){
                     d=new DataRow();
                     d=(DataRow)lista.get(i);
                     String sql="UPDATE banorte_datarows SET header="+HeaderId+" WHERE iddatarows="+d.getIddatarows()+";";
                     pdb.update(sql);
                 }
             }catch(SQLException exs)
                {
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, exs);
                }catch(Exception ge){
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge);
                }finally {
                       try {
                               pdb.close();
                       }catch(Exception ge1){
                               Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge1);
                       }
                     }
         }

        public  void updateDataRowDelete(int iddatarow,int valido){
        String sql="";
         DBWRAP pdb = new DBWRAP();
                ResultSet superRs;
                int idRs;
        try {
             sql="UPDATE banorte_datarows set valido="+valido+" WHERE iddatarows="+iddatarow;
             pdb.update(sql);
        }catch(SQLException exs)
                {
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, exs);
                }catch(Exception ge){
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge);
                }finally {
                       try {
                               pdb.close();
                       }catch(Exception ge1){
                               Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge1);
                       }
                     }
    }

        public  void updateResultTempDt(int activo,int id){
        String sql="";
         DBWRAP pdb = new DBWRAP();
                ResultSet superRs;
                int idRs;
        try {
             sql="UPDATE dispersiontempdt SET activo="+activo+" WHERE DispersionTempDt="+id+";";
             pdb.update(sql);
        } catch(SQLException exs)
                {
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, exs);
                }catch(Exception ge){
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge);
                }finally {
                       try {
                               pdb.close();
                       }catch(Exception ge1){
                               Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge1);
                       }
                     }
    }

        public  void updateTotalTempHeader(int activo,int inactivo,int id){
        String sql="";
         DBWRAP pdb = new DBWRAP();
                ResultSet superRs;
                int idRs;
        try {
             sql="UPDATE dispersiontemp SET activos="+activo+",inactivos="+inactivo+" WHERE IdDispersionTemp="+id+";";
             pdb.update(sql);
        } catch(SQLException exs)
                {
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, exs);
                }catch(Exception ge){
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge);
                }finally {
                       try {
                               pdb.close();
                       }catch(Exception ge1){
                               Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge1);
                       }
                     }
    }

        public int updateCuenta(int id,String cuenta,String tarjeta,int opc){
         int resultado=0;
          DBWRAP pdb = new DBWRAP();
                ResultSet superRs;
                int idRs;
        try {
             /*long valCuenta=0,valTarj=0;
             cuenta=cuenta.trim();
             tarjeta=tarjeta.trim();
             if(opc==1){
                valCuenta=Long.parseLong(cuenta);
             }
             if(opc==2){
                valTarj=Long.parseLong(tarjeta);
             }
             if(opc==3){
                valCuenta=Long.parseLong(cuenta);
                valTarj=Long.parseLong(tarjeta);
             }*/
             String sql="";
             switch(opc){
                 case 1:sql="UPDATE banorte_cuentas SET numCuenta='"+cuenta+"' WHERE fk_practicanteId="+id;break;
                 case 2:sql="UPDATE banorte_cuentas SET numTarjeta='"+tarjeta+"' WHERE fk_practicanteId="+id;break;
                 case 3:sql="UPDATE banorte_cuentas SET numTarjeta='"+tarjeta+"', numCuenta='"+cuenta+"' WHERE fk_practicanteId="+id;break;
             }
             pdb.update(sql);
        }catch(SQLException exs)
                {
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, exs);
                }catch(Exception ge){
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge);
                }finally {
                       try {
                               pdb.close();
                       }catch(Exception ge1){
                               Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge1);
                       }
                     }
         return resultado;
    }

        public  void updateCuentaPracticanteUpload(BanorteCuenta b){
             DBWRAP pdb = new DBWRAP();
                ResultSet superRs;
                int idRs;
        String sql="";
        long numcuenta=0;
        numcuenta=Long.parseLong(b.getNumCuenta());
        int practId=0;
        practId=b.getFk_practicanteId()-100000;
        try {
             sql="UPDATE banorte_cuentas SET numTarjeta='"+b.getNumTarjeta()+"', numCuenta='"+numcuenta+"' WHERE fk_practicanteId="+practId;
             pdb.update(sql);
        }catch(SQLException exs)
                {
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, exs);
                }catch(Exception ge){
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge);
                }finally {
                       try {
                               pdb.close();
                       }catch(Exception ge1){
                               Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge1);
                       }
                     }
    }

        public void renovarPracticante(int PracticanteId,String fechaCancelacion){
             DBWRAP pdb = new DBWRAP();
                ResultSet superRs;
                int idRs;
            Date fecha=new Date();
            SimpleDateFormat spd=new SimpleDateFormat("yyyy-MM-dd");
            String fechaStr=spd.format(fecha);
            String sql="";
            try {
                sql="UPDATE practicante SET fec_cancelacion='"+fechaCancelacion+"', status='BAJA' WHERE practicanteId="+PracticanteId;
                pdb.update(sql);
            }catch(SQLException exs)
                {
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, exs);
                }catch(Exception ge){
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge);
                }finally {
                       try {
                               pdb.close();
                       }catch(Exception ge1){
                               Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge1);
                       }
                     }
        }
        
        public int insertCuenta(int id,long cuenta,long tarjeta){
         int resultado=0;
          DBWRAP pdb = new DBWRAP();
                ResultSet superRs;
                int idRs;
        try {
             String sql="INSERT INTO banorte_cuentas(numsiga, fk_practicanteId, numTarjeta, numCuenta) ";
             sql+="VALUES(0, "+id+","+tarjeta+","+cuenta+");";
             pdb.update(sql);
        }catch(SQLException exs)
                {
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, exs);
                }catch(Exception ge){
                       Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge);
                }finally {
                       try {
                               pdb.close();
                       }catch(Exception ge1){
                               Logger.getLogger(PrefacturaMO.class.getName()).log(Level.SEVERE, null, ge1);
                       }
                     }
         return resultado;
    }

}
